<?php
require_once 'config21.php';
if (!isset($_SESSION['userid'])) {
    header('Location: login21.php');
    exit;
}

// 添加系部
if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST['add_department'])) {
    $department_name = $_POST['department_name'];
    $sql = "INSERT INTO departments (department_name) VALUES ('$department_name')";
    if ($conn->query($sql) === TRUE) {
        header('Location: department_management21.php');
        exit;
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }
}
?>
<!DOCTYPE html>
<html lang="zh-Hans">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加系部</title>
    <link rel="stylesheet" href="style.css">
    <style>
        .add-button {
            display: inline-block;
            background-color: #007bff;
            color: white;
            padding: 8px 16px;
            text-decoration: none;
            border-radius: 4px;
        }
        .add-button:hover {
            background-color: #0056d3;
        }
    </style>
</head>
<body>
    <h2>添加系部</h2>
    <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
        <label for="department_name">系部名称：</label>
        <input type="text" name="department_name" require><br>
        <input type="submit" value="添加" name="add_department">
    </form>
    <div align="right"><a href="department_management21.php" class="add-button">返回</a></div>
</body>
</html>